package com.zjx.springcloud.redis;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

@SuppressWarnings("all")
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {
    private static final Logger logger = LoggerFactory.getLogger(RedisKeyExpirationListener.class);

    public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }

    @Override
    public void onMessage(Message message, byte[] pattern) {
        String redisKey = message.toString();
        logger.info("即将要失效的Key:" + redisKey);

//        if(message.toString().startsWith(Server.PC_type+"_"+Server.server_name+"_"+Server.User_Admin_type+"_")){
////            JSONObject result=new JSONObject();
////            result.put(MsgScoketHandle.MSG_REQUEST_KEY,MsgScoketHandle.FLAG_USER_EXIT);
////            TextMessage messageInfo=new TextMessage(result.toJSONString());
////            msgScoketHandle.sendMessageToUser(message.toString(),messageInfo);
//        }else if(message.toString().startsWith(Server.PC_type+"_"+Server.server_name+"_"+Server.User_User_type+"_")){
////            JSONObject result=new JSONObject();
////            result.put(MsgScoketHandle.MSG_REQUEST_KEY,MsgScoketHandle.FLAG_USER_EXIT);
////            TextMessage messageInfo=new TextMessage(result.toJSONString());
////            msgScoketHandle.sendMessageToUser(message.toString(),messageInfo);
//
//        }
    }

}
